//
//  UIBarButtonItem+Extension.swift
//  WeiBoYH
//
//  Created by yanhui on 2017/1/5.
//  Copyright © 2017年 yanhui. All rights reserved.
//

import UIKit


extension UIBarButtonItem {
    
    convenience init(title: String, imageName: String? = nil,target: Any?, action: Selector?) {
        
        let btn = UIButton()
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        if let imgName = imageName{
            
            btn.setImage(UIImage(named:imgName), for: .normal)
            btn.setImage(UIImage(named:imgName + "_highlighted"), for: .highlighted)
        }
       
        btn.setTitle(title, for: .normal)
        
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        if let ac = action {
            btn.addTarget(target, action: ac, for: .touchUpInside)
        }
    
        btn.sizeToFit()
        
        
        
        self.init()
        self.customView = btn
    }
}
